package logic

import (
	"context"
	"fmt"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TiZiShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTiZiShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TiZiShowLogic {
	return &TiZiShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TiZiShowLogic) TiZiShow(in *tiebarpc.TiZiShowRequest) (*tiebarpc.TiZiShowResponse, error) {
	// todo: add your logic here and delete this line
	var tz mysql.TieZi
	mysql.DB.Debug().Where("id = ?", in.TieZiId).Find(&tz)
	if tz.ID == 0 {
		return nil, fmt.Errorf("没有该帖子,查找不到")
	}
	return &tiebarpc.TiZiShowResponse{
		TieZiId: int64(tz.ID),
		TieId:   tz.TieId,
		UserId:  tz.UserId,
		Title:   tz.Title,
		Content: tz.Content,
		Likes:   tz.Likes,
	}, nil
}
